<?php
/**
 * 首页
 * @author chenlisong E-mail:chenlisong1021@163.com 
 * @version 创建时间：2016年12月3日 上午9:52:18 
 * 类说明
 */
class IndexAction extends BaseAction{ 
	
	Public function index(){
		$Banner = M('Banner');$Meetingplace = M('Meetingplace');$MeetingplaceProduct = M('MeetingplaceProduct');$Product = M('Product');$Type = M('Type');
		$param = $this->param;
		$data['bannerList'] = $Banner->where('flag = 1 and is_on = 1 and type != 5')->field('id,title,img_web as img,type,url')->order('seq asc')->select();
		//活动专场
		$data['hdMeeting'] = $Banner->where('flag = 1 and is_on = 1 and type = 5')->field('id,img_web as img,type,url')->find();
		//特价疯抢（有且仅有一个）
		$map2['flag'] = 1;
		$map2['type'] = 3;
		$map2['is_on'] = 1;
		$id = $Meetingplace->where($map2)->getField('id');
		if(!empty($id)){
			$productIds = $MeetingplaceProduct->where('meetingplace_id = '.$id)->getField('GROUP_CONCAT(product_id)');
		}
		if(!empty($productIds)){
			$map3['flag'] = 1;
			$map3['is_on'] = 1;
			$map3['id'] = array('in',$productIds);
			$data['tjMeetingId'] = $id;
			$data['tjMeetingProductList'] = $Product->where($map3)->field('id,name,photo,price,spec')->order("seq asc")->select();
		}
		//icon
		$typeArr = C('SYSTEM_ICON_TYPE_ID');
		$tmap['flag'] = 1;
		$tmap['reserve'] = 1;
		$tmap['id'] = array('in',$typeArr);
		$iconArr = $Type->where($tmap)->field('id as typeId,type_name as typeName,icon')->order("FIELD(id,".implode(',', $typeArr).")")->select();
		//产品
		foreach($iconArr as $key=>$val){
			$map4['flag'] = 1;
			$map4['is_on'] = 1;
			$map4['type_id'] = $val['typeId'];
			$data['tjProductList'][$key]['typeId'] = $val['typeId'];
			$data['tjProductList'][$key]['typeName'] = $val['typeName'];
			$data['tjProductList'][$key]['icon'] = "/Uploads/icon/web_".$typeArr[$key].".png";
			$data['tjProductList'][$key]['productList'] = $Product->where($map4)->order('rand()')->field('id,name,photo,price,spec')->limit(3)->select();
		}
		$this->assign('data',$data);
		$this->display();
	}
	
}
